package com.example.clublesson01.fragments.lookcar

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ToastUtils
import com.bw.kf.lib_base.base.BaseViewModel
import com.bw.kf.lib_base.entity.GroupIndexEntity
import com.bw.kf.lib_base.entity.LookCarBannerEntity
import com.bw.kf.lib_base.entity.LookCarEntity
import com.bw.kf.lib_base.entity.Res

import kotlinx.coroutines.launch

class LookCarViewModel:BaseViewModel() {
    val success = MutableLiveData<Res<MutableList<LookCarEntity>>>()
    val fail = MutableLiveData<String>()
    fun getGroupList(){
        viewModelScope.launch {
            try {
                success.value =apiService.getGroupList()
            } catch (e: Exception) {
                fail.value = e.message
                Log.i("TAG", "getGroupList: "+e.message)
                ToastUtils.showLong(e.message)
            }
        }
    }
    val successBanner = MutableLiveData<LookCarBannerEntity>()
    val failBanner = MutableLiveData<String>()
    fun getBannerList(){
        viewModelScope.launch {
            try {
                successBanner.value =apiService.getBannerList()
            } catch (e: Exception) {
                failBanner.value = e.message
                Log.i("TAG", "getGroupList: "+e.message)
                ToastUtils.showLong(e.message)
            }
        }
    }

    val successGroup = MutableLiveData<GroupIndexEntity>()
    val failGroup = MutableLiveData<String>()
    fun getGroupIndex(){
        viewModelScope.launch {
            try {
                successGroup.value =apiService.getGroupIndexList()
            } catch (e: Exception) {
                failGroup.value = e.message
                Log.i("TAG", "getGroupList: "+e.message)
                ToastUtils.showLong(e.message)
            }
        }
    }
}